package edu.mis.model;

import java.util.*;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.base.BaseOrderDetail;


@SuppressWarnings("serial")
public class OrderDetail extends BaseOrderDetail<OrderDetail> {


	public static final OrderDetail dao = new OrderDetail().dao();

    private RoomType roomType;
    private OrderList orderList;


	/**
	 * 表关联查询得到菜品的菜品号
	 * 类型：订单为1：N关系，得到菜品对象的类型
	 * @return
	 */
	public List<Record> findAllOrderDetailsWithRoomType(String roomTypeId){
		return Db.find("SELECT d.id,d.qty,t.typeName,t.price FROM(SELECT * FROM order_detail  WHERE roomTypeId=?) d LEFT JOIN room_type t on d.roomTypeId=t.id",roomTypeId);
	}


	public List<Record> findAllRecord() {
        return Db.find("SELECT d.*,t.typeName,t.price FROM order_detail d LEFT JOIN room_type t ON d.roomTypeId=t.id");
	}


	public List<OrderDetail> findAll(){
		return OrderDetail.dao.find("SELECT * FROM order_detail");
	}
	public List<OrderDetail> findAllByOrderListId(Integer id){
		return OrderDetail.dao.find("SELECT * FROM order_detail WHERE orderListId=?", id);
	}




	/**
	 * 表关联查询_得到订单详细的菜品
	 * 权限:用户为1:N关系，得到订单详细的菜品对象。
	 * @return
	 */
	public RoomType findRoomTypeByRoomTypeId(Integer roomTypeId){
		return RoomType.dao.findById(roomTypeId);
	}

	public void setRoomType(RoomType roomType) {
		this.setRoomTypeId(roomType.getId());
		this.roomType = roomType;

	}

	public RoomType getRoomType() {
		return roomType;
	}

	public OrderList getOrderList() {
		return orderList;
	}

	public void setOrderList(OrderList orderList) {
		this.setOrderListId(orderList.getId());
		this.orderList = orderList;
	}



}
